#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>        // 哈希

using namespace std;


class Shape {
public:
    virtual void draw() = 0;
};


class Circle 
    : public Shape {
public:
    explicit Circle(string color)
        : color_(move(color)) {
    }

    void setX(int x) {
        x_ = x;
    }

    void setY(int y) {
        y_ = y;
    }

    void setRadius(int radius) {
        radius_ = radius;
    }

    void draw() {
        cout << "Circle: Draw() [Color : " << color_
        << ", x : " << x_ << ", y :" << y_ <<", radius :" << radius_ << endl;
    }
private:
    string color_;
    int x_;
    int y_;
    int radius_;
};


/*
\ brief:   形状工厂
\ author: 清晨与猫鱼
*/
class ShapeFactory {
public:

/*
\ brief:   返回圆形
\ author: 清晨与猫鱼
*/
    static Shape* getCircle(string color) {
        // 查找哈希容器中，是否有该颜色的圆
        auto it = ShapeFactory::circleMap_.find(color);

        // 如果没有，则动态分配一个
        if (it == ShapeFactory::circleMap_.end()) {
            Shape* circle = new Circle(color);
            unique_ptr<Shape> ptr(circle);
            ShapeFactory::circleMap_.insert({color, move(ptr)});
            return circle;
        }

        // 有的话，直接返回该指针
        return it->second.get();
    }

private:
    static unordered_map<string, unique_ptr<Shape>> circleMap_;     // 圆形哈希
};

unordered_map<string,unique_ptr<Shape>> ShapeFactory::circleMap_;       // 初始化
